<?php if(!defined('HOST'))die('not access');?>
<style type="text/css">
    body{margin:0px;}  
.line-1{width:100%;height:30px;}
#bg{width:100%;height:100%;top:0px;left:0px;position:absolute;filter: Alpha(opacity=50);opacity:0.5; background:#000000; display:none;}  

</style>
<script>
var c;
$(document).ready(function(){
    {params};
    js.ajax(js.getajaxurl('getNowYearMergeProject','luck|index','cg'),{},function(s){
        var content = "<option value=''>-请选择项目-</option>";
        var obj=$("select[name='projectnum']");
        $.each(s, function(i, field){
            content += "<option value='"+field.id+"' data-id='"+field.projectid+"'>"+field.name+"</option>";
        });
        if (obj.length>0) {
            obj.html(content);
        }
    },'get,json',false,'');
    summaryLists_zhuanjia(params,true);
});
function summaryLists_zhuanjia(params){

        var a = $('#veiw_{rand}').bootstable({
            tablename:'a_cqzz',celleditor:true,sort:'id',dir:'desc',modedir:'luck|index:cg',params:params,checked:false,fanye:true,
            url:js.getajaxurl('getCqzzList','luck|index','cg'),data:params,fanye:true,
            columns:[{
                text:'抽取标题',dataIndex:'title'
            },{
                text:'对应项目',dataIndex:'name'
            },{
                text:'抽取时间',dataIndex:'addtime'
            },{
                text:'抽取人数',dataIndex:'sum'
            },{
                text:'当前状态',dataIndex:'type_text'
            },{
                text:'操作',width:200,dataIndex:'id',renderer:function(s,d){
                    if(d.type==1){
                        return '<button onclick="shanchu('+d.id+',1)" class="btn btn-primary btn-xs" style="background-image: linear-gradient(#eb5454, #e72f2f 60%, #f90404);background-color: #e81f1f;border-color: #e81f1f;">删除</button><button onclick="wancheng('+d.id+',1)" class="btn btn-primary btn-xs" style="margin-left:5px;">标记完成</button>';
                    }else{
                        return '<button onclick="shanchu('+d.id+',1)" class="btn btn-primary btn-xs" style="background-image: linear-gradient(#eb5454, #e72f2f 60%, #f90404);    background-color: #e81f1f;border-color: #e81f1f;">删除</button>';
                    }
                }
            }],
            rendertr:function(d){
                var s = '';
               
                return s;
            },
            //点击行事件
            celldblclick:function(){
                var id=a.changedata.id;
                var urls = 'cg,index,coujiang,cqid='+id;
                addtabs({num:'gather-admin',url:urls,icons:'',name:'抽取记录'});
            },
        });

        
        c = {
            search:function(){
                var n=$('#name').val();
                var t=$('#title').val();
                summaryLists_zhuanjia({name:n,title:t},true);
            }
        };
        js.initbtn(c);
}   
</script>
<div>
    <div class="line-1">
        <div class="form-group col-sm-4">
            <div class="row">
                <div class="col-sm-4">
                    <input class="form-control" id="title" placeholder="输入抽取标题" />
                </div>
                <div class="col-sm-4">
                    <input class="form-control" id="name" placeholder="输入对应项目" />
                </div>
                <div class="col-sm-2">
                    <button class="btn btn-default" click="search" type="button">搜索</button>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-8">
            <div class="row">
                <div class="col-sm-4">
                    <input class="form-control" id="title_cqzz" placeholder="填写抽取名称">
                </div>
                <div class="col-sm-4">
                    <select id="projectnum" name="projectnum" style="width:100%;" class="form-control">
                        <option value=''>-请选择项目-</option> 
                    </select>
                </div>
                <div class="col-sm-2">
                    <button onclick="mergeProject()"  type="button" clickadd="true" class="btn btn-primary">发起抽取</button>&nbsp;
                </div>
            </div>
        </div>
    </div>
</div>
<div class="blank10"></div>
<div id="veiw_{rand}"></div>
<script>
function mergeProject(){
    var title = $("#title_cqzz").val();
    if(title == "") {
        layer.msg("抽取名称不能为空", {icon: 5});
        return ;
    }
    var pid = $('#projectnum option:selected').val(); 
    if(pid == "" || pid <1) {
        layer.msg("抽取项目不能为空", {icon: 5});
        return ;
    }
    js.ajax(js.getajaxurl('faqi','luck|index','cg'),{ title:title,pid:pid},function(s){
        layer.msg(s, {icon: 6});
        {params};
        summaryLists_zhuanjia(params);
        return ;
        //刷新界面
    },'get,json',false,'');
}
function shanchu(id){
    js.confirm('确认删除吗？', function(r){
        console.log(r);
        if(r=='yes'){
            js.ajax(js.getajaxurl('shanchu','luck|index','cg'),{id:id},function(s){
                layer.msg(s, {icon: 6});
                {params};
                summaryLists_zhuanjia(params);
                return ;
                //刷新界面
            },'get,json',false,'');
        }
    });
}
function wancheng(id){
    js.confirm('标记完成后不能进行操作，确认标记吗？', function(r){
        console.log(r);
        if(r=='yes'){
            js.ajax(js.getajaxurl('wancheng','luck|index','cg'),{id:id},function(s){
                layer.msg(s, {icon: 6});
                {params};
                summaryLists_zhuanjia(params);
                return ;
                //刷新界面
            },'get,json',false,'');
         }
    });
}
</script>